package com.example.demo.job;

import com.example.demo.beans.entity.ImmeEmp;
import com.example.demo.service.EmpService;
import com.example.demo.service.MailService;
import lombok.extern.log4j.Log4j2;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Log4j2
public class AutoSendMailJob implements Job {
    @Autowired
    MailService mailService;

    @Autowired
    EmpService empService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("执行发送邮件定时任务");

        List<ImmeEmp> emps = empService.getAllEmp();
        emps.stream().forEach(item -> {
            log.info("邮件接收人：{},邮箱：{}",item.getEmpname(),item.getEmail());
            String title = "上班通知";
            String content = "从明天开始需要上班！";
            mailService.sendMail(title,content,item.getEmail());
        });
    }
}
